<template>
    <div class="app">
        <top></top>
        <!-- <h1>你好世界</h1> -->
        <van-form @submit="onSubmit">
            <van-field v-model="username" name="username" label="用户名" placeholder="用户名"
                :rules="[{ required: true, message: '请填写用户名' }]" />
            <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
                :rules="[{ required: true, message: '请填写密码' }]" />
<!-- 
            <van-field v-model="vercode" center clearable label="短信验证码" placeholder="请输入短信验证码">
                <template #button>
                    <van-button size="small" type="primary" native-type="button" @click="send">发送验证码</van-button>
                </template>
            </van-field> -->

            <div style="margin: 16px;">
                <van-button round block type="info" native-type="submit">登录</van-button>
            </div>

        </van-form>
    <router-link to="/my">注册账号</router-link> | <router-link to="/" >忘记密码</router-link>
     <router-link to="/gerenziliao">跳到个人</router-link> 
        <tabars></tabars>
    </div>  
</template>
<script>
import { getLine } from '@/api/home.js'
import tabars from '@/components/bottom'
import top from '@/components/top'
import Top from '@/components/top.vue';
export default {
    name: 'issue',
    components: {
    [tabars.name]: tabars,
    [top.name]: top,
    Top
},
    data() {
        return {
            username: '',
            password: '',
            vercode: ''
        };
    },
    
    mounted() {
    },
    created() {
    
    },
    methods: {
        onSubmit(values) {
            console.log('submit', values);
            console.log(values.username,values.密码)
           
        this.getdl()

        },
//         send(){
//   getLine('/user/sendSms',{ mobile: this.username, type: 'register' }).then(res => {
//             console.log(res)
//         })
//         },
        getdl() {
            let { username, password} = this
            getLine('/user/login', { password, username}).then(res => {
                console.log(res)
              console.log(res.data.userInfo.avatar)
                if(res.data.code==0){
                    this.$store.commit('changetrue')
                      let {token , uid , tokenExpired , userInfo}=res.data
                      console.log('你好世界')
                     
                    localStorage.setItem('dw-token',token)
                          localStorage.setItem('dw-uid',uid)
                          localStorage.setItem('dw-tokenExpired',tokenExpired)  
                           localStorage.setItem('dw-username',this.username)
                           localStorage.setItem('dw-avatar',userInfo.avatar)
              localStorage.setItem('dw-anickname',userInfo.nickname)
                this.$store.commit('getvuexname',localStorage.getItem('dw-anickname'))
                console.log('这是vux',this.$store.state.vuexname)
                this.$store.commit('getvuexuserimgsrc',localStorage.getItem('dw-avatar'))
                console.log(this.$store.state.vuexuserimgsrc)


                         this.$router.push('/gerenziliao')
                }
                if(res.data.code!=0){
                    console.log(res.data.msg)
                }
            })
        },


    },
}
</script>
<style>


</style>